﻿#region Using directives

using System;
using System.ComponentModel;

#endregion

namespace NetROS.Tiers.Entities
{	
	///<summary>
	/// An object representation of the 'tblObracunOsobaPrimanje' table. [No description found the database]	
	///</summary>
	/// <remarks>
	/// This file is generated once and will never be overwritten.
	/// </remarks>	
	[Serializable]
	[CLSCompliant(true)]
	public partial class ObracunOsobaPrimanje : ObracunOsobaPrimanjeBase
	{		
		#region Constructors

		///<summary>
		/// Creates a new <see cref="ObracunOsobaPrimanje"/> instance.
		///</summary>
		public ObracunOsobaPrimanje():base()
		{

		    DatumDo = DateTime.Today;
            DatumOd = DateTime.Today;

        }
        #endregion
        protected override void AddValidationRules()
        {
            base.AddValidationRules();
            //Validation rules based on database schema.
            ValidationRules.AddRule(Validation.CommonRules.GreaterThanOrEqualToValue<Decimal?>
                , new Validation.CommonRules.CompareValueRuleArgs<Decimal?>("Iznos", 0));
            ValidationRules.AddRule(Validation.CommonRules.GreaterThanOrEqualToValue<Decimal?>
                , new Validation.CommonRules.CompareValueRuleArgs<Decimal?>("Postotak", 0));
            ValidationRules.AddRule(Validation.CommonRules.GreaterThanOrEqualToValue<Int32?>
    , new Validation.CommonRules.CompareValueRuleArgs<Int32?>("Sati", 0));
            ValidationRules.AddRule(Validation.CommonRules.GreaterThanOrEqualToValue<Decimal?>
    , new Validation.CommonRules.CompareValueRuleArgs<Decimal?>("Satnica", 0));
            
            ValidationRules.AddRule(ValidateDatumOdDoTestIntervalima, new NetROS.Tiers.Entities.Validation.ValidationRuleArgs("DatumOd", "Datum od"));
            ValidationRules.AddRule(ValidateDatumDoOdTestIntervalima, new NetROS.Tiers.Entities.Validation.ValidationRuleArgs("DatumDo", "Datum do"));
            ValidationRules.AddRule(ValidateIDTipPrimanja, new NetROS.Tiers.Entities.Validation.ValidationRuleArgs("IDPrimanjeTip", "Tip primanja"));
//            ValidationRules.AddRule(ValidateIDTipPrimanja, new NetROS.Tiers.Entities.Validation.ValidationRuleArgs("IDPrimanjeTip", "Tip primanja"));
        }


        private bool ValidateDatumOdDoTestIntervalima(object target, NetROS.Tiers.Entities.Validation.ValidationRuleArgs e)
        {
              if (DatumOd > DatumDo)
               {
                   e.Description = "Datum od veći od datuma do";
                   return false;
               }
            return true;    
        }
        private bool ValidateIDTipPrimanja(object target, NetROS.Tiers.Entities.Validation.ValidationRuleArgs e)
        {
            if (this.IDPrimanjeTip == 0)
            {
                e.Description = "Izaberite tip";
                return false;
            }
            return true;
        }
        private bool ValidateDatumDoOdTestIntervalima(object target, NetROS.Tiers.Entities.Validation.ValidationRuleArgs e)
        {
            if (DatumOd > DatumDo)
            {
                e.Description = "Datum od veći od datuma do";
                return false;
            }
            return true;
        }

        [DescriptionAttribute(""), System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)]
        [DataObjectField(false, false, true)]
        public virtual System.Decimal? IDPrimanjeTipSourceNetoIznos
        {
            get
            {
                if (IDPrimanjeTipSource != null && IDPrimanjeTipSource.IDVrstaRaspodjele == 1)
                {
                    return Iznos;
                }
                return null;
            }
        }

        [DescriptionAttribute(""), System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)]
        [DataObjectField(false, false, true)]
        public virtual System.Decimal? IDPrimanjeTipSourceBrutoIznos
        {
            get
            {
                if (IDPrimanjeTipSource != null && IDPrimanjeTipSource.IDVrstaRaspodjele != 1)
                {
                    return Iznos;
                }
                return null;
            }
        }


	}
}

